<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/rp/common/taglib.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>">
    
    <title>按钮管理</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	
	<script src="rp/scripts/boot.js" type="text/javascript"></script>
	
	<style type="text/css">
	   	
    </style>
	
  </head>
  
  <body class="body-fit">
  	
  	<div style="width:100%;">
        <div class="mini-toolbar" style="padding:1px;border-top:0;border-left:0;border-right:0;">
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" onclick="addRow()"><i class="fa fa-plus fa-lg"></i> 新增</a>
                        <a class="mini-button" onclick="saveRows()"><i class="fa fa-floppy-o fa-lg"></i> 保存</a>
                        <a class="mini-button mini-button-danger" onclick="removeRows()"><i class="fa fa-trash-o fa-lg"></i> 删除</a>       
                        <!-- <a class="mini-button" onclick="">导出</a>       
                        <a class="mini-button" onclick="">导入</a> -->       
                    </td>
                    <td style="white-space:nowrap;">
                        
                    </td>
                </tr>
            </table>           
        </div>
    </div>
    <div class="mini-fit">
	  	<div id="buttonGrid" class="mini-datagrid" 
	  		style="width: 100%; height: 100%;" borderStyle="border:0;"
	    	url="rp/system/buttonMng/getButtonsByPage" idField="id" allowResize="true" pageSize="20"
	    	allowCellEdit="true" allowCellSelect="true" multiSelect="true" 
	        editNextOnEnterKey="true" editNextRowCell="true" allowCellValid="true">
		    <div property="columns">
		        <div type="indexcolumn" headerAlign="center">序号</div>
		        <div type="checkcolumn"></div>
		        <div name="type" field="type" vtype="required" width="80" headerAlign="center" allowSort="true">
		        	按钮类型
		        	<input property="editor" class="mini-textbox" style="width:100%;"/>
		        </div>    
		        <div field="text" vtype="required" width="80" headerAlign="center" allowSort="true">
		        	按钮文本
		        	<input property="editor" class="mini-textbox" style="width:100%;"/>
		        </div> 
		        <div field="createDate" width="100" headerAlign="center" allowSort="true" renderer="onDateRenderer">
		        	创建日期
		        </div>                
		    </div>
		</div>
		
	</div>
  	
	<script type="text/javascript">
		var grid;
		var moduleAlias;
	
		$(function(){
			mini.parse();
			grid = mini.get("buttonGrid");
			
		});
		
		function addRow() {         
            var newRow = { type: "" };
            grid.addRow(newRow, 0);
            grid.beginEditCell(newRow, "type");
        }
		
		function saveRows(){
			grid.validate();
			if (grid.isValid() == false) {
                var error = grid.getCellErrors()[0];
                grid.beginEditCell(error.record, error.column);
                return;
            }
			
            var data = grid.getChanges();
            var json = rp_encode(data);
            grid.loading("保存中，请稍等......");
            rp_ajax("rp/system/buttonMng/saveButtons", {data: json, moduleAlias:moduleAlias}, function(text){
            	grid.reload();
            });
		}
		
		function removeRows(){
			var rows = grid.getSelecteds();
			if(rows.length == 0){
				mini.alert("请勾选需要删除的记录...");
			}else{
				mini.confirm("确定删除记录吗？", "友情提示",
		            function (action) {
		                if (action == "ok") {
		                    var json = rp_encode(rows);
		                    if (rows.length > 0) {
		                    	rp_ajax("rp/system/buttonMng/deleteButtons", {data: json}, function(text){
		                    		grid.reload();
		                        });
		                    }
		                }
		            }
		        );
			}
		}
		
		function initGrid(_moduleAlias){
			moduleAlias = _moduleAlias;
			grid.load({moduleAlias:_moduleAlias});
		}
		
	</script>
  </body>
</html>
